JS 箭頭函式


Posted by fang on 2020-06-22

單純記錄一下兩者的差別,一般的 function:

var arr = [1, 2, 3, 4, 5]
console.log(
  arr
    .filter(function(value) {
      return value > 1
    })
    .map(function(value) {
      return value * 2
    })
)

使用箭頭函式:

var arr = [1, 2, 3, 4, 5]
console.log(
  arr
    .filter(value => value > 1)
    .map(value => value * 2)
)

#javascript #箭頭函式







Related Posts

Leetcode 刷題 pattern - Fast & Slow Pointer

Leetcode 刷題 pattern - Fast & Slow Pointer

D56_W7 HW3 任務拆解、寫作業

D56_W7 HW3 任務拆解、寫作業

深入探討 JavaScript 中的參數傳遞:call by value 還是 reference?

深入探討 JavaScript 中的參數傳遞:call by value 還是 reference?


Comments